package com.lili.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lili.controller.request.*;
import com.lili.po.*;
import com.lili.service.OrderService;
import com.lili.vo.MyPage;
import com.lili.vo.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("order")
@Slf4j
public class OrderController {
    @Autowired
    OrderService orderService;

    @RequestMapping("selectUserOrderList")
    public ResponseResult selectXasUserOrderGoods(@RequestBody XasUserOrderGoodsRequest xasUserOrderGoodsRequest) {
        ResponseResult responseResult = new ResponseResult();
        MyPage myPage = new MyPage();
        BeanUtils.copyProperties(xasUserOrderGoodsRequest, myPage);
        IPage<XasUserOrderGoods> iPage = orderService.selectXasUserOrderGoods(xasUserOrderGoodsRequest);
        myPage.setTotal(iPage.getTotal());
        myPage.setRecords(iPage.getRecords());
        responseResult.setData(myPage);
        return responseResult;
    }


    @RequestMapping("updateUserOrderList")
    public ResponseResult updateUserOrderList(@RequestBody XasOrderGoodsList xasOrderGoodsList) {
        ResponseResult responseResult = new ResponseResult();
        orderService.updateUserOrderList(xasOrderGoodsList);
        return responseResult;
    }

//    @RequestMapping("updateUserOrderList")
//    public ResponseResult updateUserOrderList(@RequestBody XasUserOrderGoods xasUserOrderGoods) {
//        ResponseResult responseResult = new ResponseResult();
//        orderService.updateUserOrderList(xasUserOrderGoods);
//        return responseResult;
//    }

    @RequestMapping("selectXasOrderBillList")
    public ResponseResult selectXasOrderBillList(@RequestBody XasOrderBillListRequest xasOrderBillListRequest) {
        ResponseResult responseResult = new ResponseResult();
        List<XasOrderBillList> xasOrderBillLists = orderService.selectXasOrderBillList(xasOrderBillListRequest);
        responseResult.setData(xasOrderBillLists);
        return responseResult;
    }

    @RequestMapping("selectXasOrderBill")
    public ResponseResult selectXasOrderBill(@RequestBody XasOrderBillListRequest xasOrderBillListRequest) {
        ResponseResult responseResult = new ResponseResult();
        XasOrderBillList xasOrderBillList = orderService.selectXasOrderBill(xasOrderBillListRequest);
        responseResult.setData(xasOrderBillList);
        return responseResult;
    }


    @RequestMapping("updateXasOrderBillList")
    public ResponseResult updateXasOrderBillList(@RequestBody XasOrderBillList xasOrderBillList) {
        ResponseResult responseResult = new ResponseResult();
        orderService.updateXasOrderBillList(xasOrderBillList);
        return responseResult;
    }

    @RequestMapping("addXasOrderBillList")
    public ResponseResult addXasOrderBillList(@RequestBody XasOrderBillList xasOrderBillList) {
        ResponseResult responseResult = new ResponseResult();
        orderService.addXasOrderBillList(xasOrderBillList);
        return responseResult;
    }

    @RequestMapping("selectXasOrderGoodsList")
    public ResponseResult selectXasOrderGoodsList(@RequestBody XasOrderGoodsListRequest xasOrderGoodsListRequest) {
        ResponseResult responseResult = new ResponseResult();
        IPage<XasOrderGoodsList> xasOrderGoodsLists = orderService.selectXasOrderGoodsList(xasOrderGoodsListRequest);
        responseResult.setData(xasOrderGoodsLists);
        return responseResult;
    }


    @RequestMapping("selectXasUserOrderRecharge")
    public ResponseResult selectXasUserOrderRecharge(@RequestBody XasUserOrderRechargeRequest xasUserOrderRechargeRequest) {
        ResponseResult responseResult = new ResponseResult();
        MyPage myPage = new MyPage();
        BeanUtils.copyProperties(xasUserOrderRechargeRequest, myPage);
        IPage<XasUserOrderRecharge> iPage = orderService.selectXasUserOrderRecharge(xasUserOrderRechargeRequest);
        myPage.setTotal(iPage.getTotal());
        myPage.setRecords(iPage.getRecords());
        responseResult.setData(myPage);
        return responseResult;
    }


    @RequestMapping("selectXasUserOrderWithdraw")
    public ResponseResult selectXasUserOrderWithdraw(@RequestBody XasUserOrderWithdrawRequest xasUserOrderWithdrawRequest) {
        ResponseResult responseResult = new ResponseResult();
        MyPage myPage = new MyPage();
        BeanUtils.copyProperties(xasUserOrderWithdrawRequest, myPage);
        IPage<XasUserOrderWithdraw> iPage = orderService.selectXasUserOrderWithdraw(xasUserOrderWithdrawRequest);
        myPage.setTotal(iPage.getTotal());
        myPage.setRecords(iPage.getRecords());
        responseResult.setData(myPage);
        return responseResult;
    }


    @RequestMapping("examineXasUserOrderWithdraw")
    public ResponseResult examineXasUserOrderWithdraw(@RequestBody XasUserOrderWithdraw xasUserOrderWithdraw) {
        log.info(xasUserOrderWithdraw.getId());
        boolean flag = orderService.examineXasUserOrderWithdraw(xasUserOrderWithdraw.getId());
        return new ResponseResult(flag);
    }

    @RequestMapping("examineRejectXasUserOrderWithdraw")
    public ResponseResult examineRejectXasUserOrderWithdraw(@RequestBody XasUserOrderWithdraw xasUserOrderWithdraw) {
        log.info(xasUserOrderWithdraw.getId());
        boolean flag = orderService.examineRejectXasUserOrderWithdraw(xasUserOrderWithdraw.getId());
        return new ResponseResult(flag);
    }


    @RequestMapping("countOrder")
    public ResponseResult countOrder(@RequestBody XasUserBalanceRecordsRequest xasUserBalanceRecordsRequest) {
        List<Map<String, Double>> result = orderService.countOrder(xasUserBalanceRecordsRequest.getStartTime(), xasUserBalanceRecordsRequest.getEndTime());
        ResponseResult responseResult = new ResponseResult();
        responseResult.setData(result);
        return responseResult;
    }

    @RequestMapping("countTotalOrder")
    public ResponseResult countTotalOrder(@RequestBody XasUserBalanceRecordsRequest xasUserBalanceRecordsRequest) {
        ResponseResult responseResult = new ResponseResult();
        List<Map<String, Double>> result = orderService.countTotalOrder();
        responseResult.setData(result);
        return responseResult;
    }


}
